/* eslint-disable react/display-name */
import React, { useState } from 'react';
import { Button, Upload, Dropdown, Menu } from 'antd';

export default (props) => {
  const {
    onPrint,
    onImport: propsImport,
    download = () => {},
    print = () => {},
    undo,
    redo,
    refresh,
    reset,
    simulate,
    submit,
    setForm,
  } = props;

  const [simulateActive, setSimulateActive] = useState(false);

  const onImport = (file) => {
    const reader = new FileReader();
    reader.readAsText(file, 'utf-8');
    reader.onload = () => {
      // console.log(reader.result);
      propsImport && propsImport(reader.result);
    };

    return false;
  };

  const onSimulate = () => {
    setSimulateActive(!simulateActive);
    simulate();
  };

  if (simulateActive) {
    return (
      <div className="comp-foot">
        <Button type="primary" onClick={onSimulate}>
          退出模拟
        </Button>
      </div>
    );
  }

  return (
    <div className="comp-foot">
      <div>
        <Upload beforeUpload={onImport}>
          <Button>导入bpmn</Button>
        </Upload>

        <Dropdown.Button
          overlay={
            <Menu>
              <Menu.Item key="2" onClick={download('xml')}>
                下载XML
              </Menu.Item>
              <Menu.Item key="3" onClick={download('svg')}>
                下载SVG
              </Menu.Item>
              <Menu.Item key="4" onClick={download('bpmn')}>
                下载BPMN
              </Menu.Item>
            </Menu>
          }
        >
          下载
        </Dropdown.Button>

        <Dropdown.Button
          overlay={
            <Menu>
              <Menu.Item key="1" onClick={print('xml')}>
                打印XML
              </Menu.Item>
              <Menu.Item key="2" onClick={print('json')}>
                打印JSON
              </Menu.Item>
            </Menu>
          }
        >
          打印
        </Dropdown.Button>
      </div>

      <div>
        <Button onClick={undo}>撤销</Button>
        <Button onClick={redo}>恢复</Button>
        <Button onClick={refresh}>重新绘制</Button>
        <Button onClick={reset}>重置视图并居中</Button>
      </div>

      <div>
        <Button onClick={setForm}>设置表单</Button>
        <Button type="primary" onClick={onSimulate}>
          模拟
        </Button>
        <Button onClick={submit}>提交</Button>
      </div>
    </div>
  );
};
